﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace Adams.Admin.DataAccess.Pages
{
    public static class Common
    {
        public static Adams.Shared.Entities.Pages.PageCollection GetPagesBySearch(string term)
        {
            var data = new Adams.Shared.Entities.Pages.PageCollection();

            using (SqlDataReader dr = DB.RunDataReader(@"
SELECT * FROM Pages.Pages WHERE Title LIKE '%" + term + @"%' OR Url LIKE '%" + term + @"%'
", CommandType.Text))
            {
                while (dr.Read())
                {
                    var page = new Adams.Shared.Entities.Pages.Page();
                    page.ID = dr["PageID"].DbInt();
                    page.Title = dr["Title"].DbString();
                    page.Url = dr["Url"].DbString();
                    data.Add(page);
                }
            }

            return data;
        }
    }
}
